#ifndef tlmServiceMsg_H
#define tlmServiceMsg_H

#include "ssw_types.h"
#include "msgbuf.h"
#include "tlmIncomingTraffic.h"
#include "tlmServiceDataInfo.h"



//## class tlmServiceMsg
class tlmServiceMsg {

public:
    //the NGTP header max length is 42,
    //all filed shall be included  and all of them are fix length
    #define TLM_NGTP_HEADER_LENGTH   42 
    
    //below define the item code in header filed
    #define TLM_NGTP_HEADER_CODE_PROTOCOL_VERSION 0x01
    #define TLM_NGTP_HEADER_CODE_VIN  0x02
    #define TLM_NGTP_HEADER_CODE_ROUTE_INFO  0x03
    #define TLM_NGTP_HEADER_CODE_MSG_UNIQUE_ID  0x04
    #define TLM_NGTP_HEADER_CODE_SERVICE_TYPE   0x05
    #define TLM_NGTP_HEADER_CODE_MESSAGE_TYPE   0x06
    #define TLM_NGTP_HEADER_CODE_DATE_TIME      0x07
    #define TLM_NGTP_HEADER_CODE_MSG_PROTOCOL_VERSION   0x08
    #define TLM_NGTP_HEADER_CODE_DATA_LENGTH            0x09
    //this defines the header item count
    #define TLM_NGTP_HEADER_CODE_COUNT 9

    //below define the item size in header filed
    #define TLM_NGTP_HEADER_SIZE_PROTOCOL_VERSION 1
    #define TLM_NGTP_HEADER_SIZE_VIN  10
    #define TLM_NGTP_HEADER_SIZE_ROUTE_INFO  2
    #define TLM_NGTP_HEADER_SIZE_MSG_UNIQUE_ID  2
    #define TLM_NGTP_HEADER_SIZE_SERVICE_TYPE   1
    #define TLM_NGTP_HEADER_SIZE_MESSAGE_TYPE   1
    #define TLM_NGTP_HEADER_SIZE_DATE_TIME      4
    #define TLM_NGTP_HEADER_SIZE_MSG_PROTOCOL_VERSION   1
    #define TLM_NGTP_HEADER_SIZE_DATA_LENGTH            3

public :
    tlmServiceMsg();
    
    tlmServiceMsg(const uint8_t* msgString, const uint32_t size);
    
    tlmServiceMsg(uint8_t srvType, uint8_t msgType);
    
    ~tlmServiceMsg();

public:
    bool_t ParseMsgHeader();

    bool_t GetValue(uint8_t& value);
    bool_t GetData(uint8_t* buf, uint32_t size);

    bool_t InitHeaderItem(const uint8_t& code);
    uint8_t GetSrvType(void) const;
    uint8_t GetMsgType(void) const;
    uint8_t GetProtocolVer(void) const;
    uint8_t * GetVin(void) ;
    uint16_t  GetRouteInfo(void) const;
    uint16_t  GetMsgUniqueId(void) const;
    uint32_t  GetYear(void) const;
    uint32_t  GetMonth(void) const;
    uint32_t  GetDay(void) const;
    uint32_t  GetHour(void) const;
    uint32_t  GetMinute(void) const;
    uint32_t  GetSecond(void) const;
    uint8_t  GetMsgProtocolVer(void) const;
    uint32_t GetDataInfoLength(void) const;
    uint8_t* GetDataInfoBuf(void) const;
    uint8_t* GetMsgBuf(void) const;
    uint32_t GetMsgLen(void) const;

    bool_t SetDataLength(uint8_t * rawDataLen);
    bool_t SetDateTime(uint8_t * rawDateTime);

    void SetDataLength(uint32_t dataLength);

    void SetProtocolVer(uint8_t protocolVer);
    void SetVin(uint8_t* vin); 
    void SetRouteInfo(uint16_t routeInfo);
    void SetMsgUniqueId(uint16_t msgUniqueId); 
    void SetSrvType(uint8_t srvType); 
    void SetMsgType(uint8_t msgType); 
    void SetYear(uint32_t year);
    void SetMonth(uint32_t month);
    void SetDay(uint32_t day);
    void SetHour(uint32_t hour);
    void SetMinute(uint32_t minute);
    void SetSecond(uint32_t second);
    void SetMsgProtcolVer(uint8_t msgProtcolVer);
    bool_t Init(void);
    bool_t Fill(void);
    void FillHeader(void);
    void TranslateDateTime(uint8_t * dateTime);

protected:
    uint32_t mMsgLen;

    uint8_t* mInMsgPtr;		//## attribute mInMsgPtr

    msgbuf mInboundMsgBuf;		//## attribute mInboundMsgBuf
    msgbuf mOutboundMsgBuf;		//## attribute mOutboundMsgBuf

    uint8_t* mDataInfoMsgPtr;		//## attribute mDataInfoMsgPtr


    //below define the header item
    uint8_t mHdProtocolVersion;		//## attribute mHdProtocolVersion
    
    uint8_t mHdVin[TLM_NGTP_HEADER_SIZE_VIN];		//## attribute mHdVin
    
    uint16_t mHdRouteInfo;		//## attribute mHdRouteInfo
    
    uint16_t mHdMsgUniqueId;		//## attribute mHdMsgUniqueId
    
    uint8_t mHdSrvType;		//## attribute mHdSrvType
    
    uint8_t mHdMsgType;		//## attribute mHdMsgType
    
    uint32_t mHdYear;
    uint32_t mHdMonth;
    uint32_t mHdDay;
    uint32_t mHdHour;
    uint32_t mHdMinute;
    uint32_t mHdSecond;

    
    uint8_t mHdMsgProtocolVersion;		//## attribute mHdMsgProtocolVersion
    
    uint32_t mHdDataLength;		//## attribute mHdDataLength


    tlmServiceDataInfo * mpDataInfo; //This pointer to the datainfo instance. the service shall derived this class to implement it.
};
#endif
